<div class="form-container">
<div class="validation-errors" id="validationErrors" style="display:none;"></div>
<?php
	Includes::IncludeFile( Includes::$FORM );
	Includes::IncludeFile( Includes::$SPACER );

	echo( form_open(base_url() . 'annualbanquet/banquet_registration/step1_process/'. $eventid . '/', array('id' => 'registerBQForm') ) );

		Spacer::Render(0, 20);
		echo('<hr />');
		Form::OpenFormItem('First Name*:', 260);
			echo( form_input(array('name'=>'firstname','id'=>'firstname','maxlength'=>'16','style'=>'width: 250px;')) );
		Form::CloseFormItem();
		Form::OpenFormItem('Last Name*:', 260);
			echo( form_input(array('name'=>'lastname','id'=>'lastname','maxlength'=>'16','style'=>'width: 250px;')) );
		Form::CloseFormItem();
		Form::OpenFormItem('Email*:', 260);
			echo( form_input(array('name'=>'email','id'=>'email','maxlength'=>'127','style'=>'width: 250px;')) );
		Form::CloseFormItem();
		Form::OpenFormItem('Re-enter Email*:', 260);
			echo( form_input(array('name'=>'emailConfirm','id'=>'emailConfirm','maxlength'=>'127','style'=>'width: 250px;')) );
		Form::CloseFormItem();
		Form::OpenFormItem('Phone#*: </br><font size="2" color="red">(xxx-xxx-xxxx)</font>', 260);
			echo( form_input(array('name'=>'phoneNumber','id'=>'phoneNumber','maxlength'=>'12','style'=>'width: 250px;')) );
		Form::CloseFormItem();

		Form::OpenFormItem('Address:', 260);
			echo( form_input(array('name'=>'address','id'=>'address','style'=>'width: 250px;')) );
		Form::CloseFormItem();
		Form::OpenFormItem('City:', 260);
			echo( form_input(array('name'=>'city','id'=>'city','style'=>'width: 250px;')) );
		Form::CloseFormItem();
		Form::OpenFormItem('State:', 260);
			$stateOptions = array(''=>'Select','AL'=>'Alabama','AK'=>'Alaska','AZ'=>'Arizona','AR'=>'Arkansas','CA'=>'California','CO'=>'Colorado','CT'=>'Connecticut','DE'=>'Delaware','DC'=>'District of Columbia','FL'=>'Florida','GA'=>'Georgia','HI'=>'Hawaii','ID'=>'Idaho','IL'=>'Illinois','IN'=>'Indiana','IA'=>'Iowa','KS'=>'Kansas','KY'=>'Kentucky','LA'=>'Louisiana','ME'=>'Maine','MD'=>'Maryland','MA'=>'Massachusetts','MI'=>'Michigan','MN'=>'Minnesota','MS'=>'Mississippi','MO'=>'Missouri','MT'=>'Montana','NE'=>'Nebraska','NV'=>'Nevada','NH'=>'New Hampshire','NJ'=>'New Jersey','NM'=>'New Mexico','NY'=>'New York','NC'=>'North Carolina','ND'=>'North Dakota','OH'=>'Ohio','OK'=>'Oklahoma','OR'=>'Oregon','PA'=>'Pennsylvania','RI'=>'Rhode Island','SC'=>'South Carolina','SD'=>'South Dakota','TN'=>'Tennessee','TX'=>'Texas','UT'=>'Utah','VT'=>'Vermont','VA'=>'Virginia','WA'=>'Washington','WV'=>'West Virginia','WI'=>'Wisconsin','WY'=>'Wyoming');
			echo( form_dropdown('state', $stateOptions, 'MA', 'id="state" style="width: 120px;" ') );
		Form::CloseFormItem();
		Form::OpenFormItem('Zip Code:', 260);
			echo( form_input(array('name'=>'zipCode','id'=>'zipCode','style'=>'width: 100px;')) );
		Form::CloseFormItem();

		Form::OpenFormItem('Number of adults & children:</br><font size="2" color="red">($50 per adult or child 2 and older)</font>', 260);
			$npoptions = array(''=>'Select','1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5', '6'=>'6', '7'=>'7', '8'=>'8', '9'=>'9', '10'=>'10');
			echo( form_dropdown('numadultreg', $npoptions, '', 'id="numadultreg" style="width: 75px;" onchange="donationHandler();"') );			
		Form::CloseFormItem();
		Form::OpenFormItem('Number of children:</br><font size="2" color="red">(ages 2 and under are free)</font>', 260);
			$npoptions = array(''=>'Select','1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5', '6'=>'6', '7'=>'7', '8'=>'8', '9'=>'9', '10'=>'10');
			echo( form_dropdown('numchildreg', $npoptions, '', 'id="numchildreg" style="width: 75px;" onchange="donationHandler();"') );			
		Form::CloseFormItem();
        Form::OpenFormItem("Are you a CMB Balavihar teacher*?:", 260);
            $istchroptions = array(''=>'Select','0'=>'No','1'=>'Yes');
            echo( form_dropdown('isteacher', $istchroptions, '', 'id="isteacher" style="width: 70px;"  onchange="donationHandler();"') );
        Form::CloseFormItem();
		Spacer::Render(0, 20);

		Form::OpenFormItem('Make a General Donation to CMB:', 260);
			echo( form_input(array('name'=>'donationamount','id'=>'donationamount','style'=>'width: 100px;', 'onchange'=>'donationHandler();')) );
		Form::CloseFormItem();
/*
		echo('<div>');
		echo('<b>Total Registration Fee: $<span id="totamount"> </span></b>');
		echo('</div>');
*/		
        echo('<div class="form-total-summary">');
        echo('<div class="form-total-key-summary">Registration Total: </div>');
        echo('<div class="form-total-value-summary">$<span id="regtot"> </span></div>');
        echo('</div>');

        echo('<div class="form-total-summary">');
        echo('<div class="form-total-key-summary">Donation Total: </div>');
        echo('<div class="form-total-value-summary">$<span id="dontot"> </span></div>');
        echo('</div>');

        echo('<div class="form-total-summary">');
        echo('<div class="form-total-key-summary">Teacher Discount: </div>');
        echo('<div class="form-total-value-summary"><span id="teacherdisc"> </span></div>');
        echo('</div>');

        echo('<div class="form-total-summary">');
        echo('<div class="form-total-key-summary"><b>Grand Total: </b></div>');
        echo('<div class="form-total-value-summary"><b>$<span id="totamount"></span></b></div>');
        echo('</div>');
        echo('<hr />');
        
        Spacer::Render(0, 20);
		echo('<hr />');
		echo('<font size="2" color="red">You are finishing the first step of registration to collect all relevant information. To complete your registration you must click the <u>Make Payment</u> button to select a method of payment.  When we receive your payment your registration will be confirmed.</font>');

        //Handle case for regtype when using back/forward button on browser
        echo "<script type='text/javascript'>\n";
        echo "var divreg = document.getElementById('regtot');";
        echo "var divdon = document.getElementById('dontot');";
        echo "var divdisc = document.getElementById('teacherdisc');";
        echo "var divtot = document.getElementById('totamount');";
        echo "var numadults = $('numadultreg').options[$('numadultreg').selectedIndex].value;";
        echo "var numchildren = $('numchildreg').options[$('numchildreg').selectedIndex].value;";
        echo "var donation = parseInt($('donationamount').value);";
        echo "if (isNaN(donation)) donation = 0;";
        echo "divdon.innerHTML = donation;";
        echo "isteacher = parseInt($('isteacher').options[$('isteacher').selectedIndex].value);"; 
        echo "var teacher_discount = 0.0;";
        echo "var tot_amount = 0.0;";
        echo "var regvalue = (50 * numadults + 0*numchildren);";
        echo "divreg.innerHTML = regvalue;";
        echo "if (isteacher == 1) {";
            echo "teacher_discount = 0.35*regvalue;";
            echo "tot_amount = regvalue + donation - teacher_discount;";
            echo "divdisc.innerHTML = '<font color=\"red\">$('+teacher_discount+')<font>';";
        echo "}";
        echo "else {";
            echo "tot_amount = regvalue + donation;";
            echo "divdisc.innerHTML = '$0';";
        echo "}";
    
        echo "if (tot_amount > 0.01)";
            echo "divtot.innerHTML = tot_amount;";
        echo "else";
            echo "divtot.innerHTML = 0;";

        echo "</script>";       
	echo( form_close() );
?>
	
	<div class="form-button-container">
		<a href="javascript: validate();"><img src="<?php echo( base_url() );?>assets/images/buttons/make_payment.gif" border="0" onmouseover="this.src = '<?php echo( base_url() );?>assets/images/buttons/make_payment.gif';" onmousedown="this.src = '<?php echo( base_url() );?>assets/images/buttons/make_payment.gif';" onmouseup="this.src = '<?php echo( base_url() );?>assets/images/buttons/make_payment.gif';" onmouseout="this.src = '<?php echo( base_url() );?>assets/images/buttons/make_payment.gif';" /></a>
	</div>

</div>

<script type="text/javascript">
	function validate()
	{
		var eventid =  "<?php echo $eventid ?>";
		new Ajax.Request(baseUrl + 'validation/banquet_validation/validate_registration/'+eventid, 
		{
			method:'post',
			parameters: Form.serialize( $('registerBQForm') ),
		  	onSuccess: function(response)
			{
				var result = response.responseText;
				
				if( result == 'VALIDATION_SUCCESS' )
				{
					$('registerBQForm').submit();
				}
				else
				{
					$('validationErrors').innerHTML = result;
					$('validationErrors').show();
					Effect.ScrollTo('validationErrors', { duration:'0.2', offset:-20 });
				}
			},
			onFailure: function(response){var result = response.responseText; $('validationErrors').innerHTML = result;
					$('validationErrors').show();alert('failed') }
		});
	}

	function numAdultsHandler()
	{
		var numadults = $('numadultreg').options[$('numadultreg').selectedIndex].value;
		var numchildren = $('numchildreg').options[$('numchildreg').selectedIndex].value;
		var donation = parseInt($('donationamount').value);
		if (isNaN(donation)) donation = 0;
		var divtot = document.getElementById('totamount');
		divtot.innerHTML = 50 * numadults + 0*numchildren + donation;
	}

	function numChildrenHandler()
	{
		var numadults = $('numadultreg').options[$('numadultreg').selectedIndex].value;
		var numchildren = $('numchildreg').options[$('numchildreg').selectedIndex].value;
		var donation = parseInt($('donationamount').value);
		if (isNaN(donation)) donation = 0;
		var divtot = document.getElementById('totamount');
		divtot.innerHTML = 50 * numadults + 0*numchildren + donation;
	}

	function donationHandler()
	{
        var divreg = document.getElementById('regtot');
        var divdon = document.getElementById('dontot');
        var divdisc = document.getElementById('teacherdisc');
        var divtot = document.getElementById('totamount');
		var numadults = $('numadultreg').options[$('numadultreg').selectedIndex].value;
		var numchildren = $('numchildreg').options[$('numchildreg').selectedIndex].value;
		var donation = parseInt($('donationamount').value);
		if (isNaN(donation)) donation = 0;
        isteacher = parseInt($('isteacher').options[$('isteacher').selectedIndex].value); 
        var teacher_discount = 0.0;
        var tot_amount = 0.0;
        var regvalue = (50 * numadults + 0*numchildren);    

        if (isteacher == 1) {
            teacher_discount = 0.35*regvalue;
            tot_amount = regvalue + donation - teacher_discount;
            divdisc.innerHTML = '<font color="red">$('+teacher_discount+')<font>';
        }
        else {
            tot_amount = regvalue + donation;
            divdisc.innerHTML = '$0';
        }
    
        if (tot_amount > 0.01)
            divtot.innerHTML = tot_amount;
        else
            divtot.innerHTML = 0;
    
        divreg.innerHTML = regvalue;
        divdon.innerHTML = donation;
	}
</script>
